import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import org.teleal.cling.controlpoint.ActionCallback;
import org.teleal.cling.model.action.ActionInvocation;
import org.teleal.cling.model.message.UpnpResponse;
import org.teleal.cling.model.meta.Service;


/**
 * Implementation of the GetSearchCapabilties action.
 * 
 * @author Sam SmithReams
 *
 */
public class SearchCapabilities extends ActionCallback
{
	private List<String> propertyNames;

	public SearchCapabilities(Service service)
	{
		super(new ActionInvocation(service.getAction("GetSearchCapabilities")));
		propertyNames = new ArrayList<String>();
	}

	public List<String> getPropertyNames()
	{
		return propertyNames;
	}

	@Override
	public void success(ActionInvocation invocation)
	{
		String searchCaps = invocation.getOutput("SearchCaps").getValue().toString();
		StringTokenizer tokenizer = new StringTokenizer(searchCaps, ",");
		while(tokenizer.hasMoreTokens())
		{
			propertyNames.add(tokenizer.nextToken());
		}
	}

	@Override
	public void failure(ActionInvocation invocation, UpnpResponse operation,
			String defaultMsg)
	{
		// Do nothing

	}
}
